package com.mr.wordcount.combine;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class WCMapper extends Mapper<LongWritable, Text, Text, LongWritable>{

	private Text out_key= new Text();
	private LongWritable out_value = new LongWritable(1);

	// 针对输入的每个keyin-valuein调用一次
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context)
			throws IOException, InterruptedException {

		System.out.println("keyin:" + key  + "---valuein:" + value);

		String[] words = value.toString().split("\t");

		for( String word : words) {
			out_key.set(word);
			// 写出数据，单词 1
			context.write(out_key, out_value);
//				context.write(new Text(word), new LongWritable(1));
		}
	}
}
